export default {
    name: 'channelDetail',
    data() {
        return {
            currentClientMethods: [],
            settings: {},
            balanceList: [],
	        wxpayList: [],
	        alipayList: [],
            unionpayList: [],
            acpayList: [],
            //--------
            balanceCheck: [],
	        wxpayCheck: [],
	        alipayCheck: [],
            unionpayCheck: [],
            acpayCheck: [],
            //--------
            settingTableTabsVal: 'APP',
            settingTableTabs:[
                { name: 'APP', icon: 'iphone', title: 'APP （客户端）' },
                { name: 'WAP', icon: 'browser', title: 'WAP （H5手机游览器）' },
                { name: 'WX', icon: 'wechat', title: 'WX（微信内置游览器）' }
            ],
            bLoading: false,
            wLoading: false,
            aLoading: false,
            uLoading: false,
            acLoading:false
        }
    },
    created() {
        this.methodSettings();
    },
    filters: {    },
    methods: {
        methodSettings() {
            this.$http.post("payChannelMethod/methodSettings", {}).then(data => {
                this.settings = data.info;
                this.balanceList = this.settings.balanceList;
                this.alipayList = this.settings.alipayList;
                this.wxpayList = this.settings.wxpayList;
                this.unionpayList = this.settings.unionpayList;
                this.acpayList = this.settings.acpayList;
                this.initSetting();
            }).catch(error => {
                console.log(error);
            });
        },
        initSetting() {
            this.$http.post("payClientMethod/clientMethods", {clientId: this.settingTableTabsVal}).then(data => {
               this.currentClientMethods = data.info;
               this.balanceCheck = [];
               this.wxpayCheck = [];
               this.alipayCheck = [];
               this.unionpayCheck = [];
               this.acpayCheck = [];
               this.setListChecked(this.acpayList,this.acpayCheck);
               this.setListChecked(this.balanceList,this.balanceCheck);
               this.setListChecked(this.wxpayList,this.wxpayCheck);
               this.setListChecked(this.alipayList,this.alipayCheck);
               this.setListChecked(this.unionpayList,this.unionpayCheck);
            }).catch(error => {
                console.log(error);
            });
        },
        setListChecked(list,newList){
            let current = this.currentClientMethods;
            for(let i =0;i<list.length;i++){
                for(let j=0;j<current.length;j++){
                    if(list[i].methodId == current[j].methodId){
                        newList.push(current[j].methodId)
                    }
                }
            }
        },
        clientMethodChange(gatewayType) {
            let _data = {
                type: gatewayType,
                clientId: this.settingTableTabsVal
            }
            if (gatewayType == "WXPAY" && this.wxpayCheck.length > 0) {
                _data.methodId = this.wxpayCheck[0];
                this.wLoading = true;
            } else if (gatewayType == "ALIPAY" && this.alipayCheck.length > 0) {
                _data.methodId = this.alipayCheck[0];
                this.aLoading = true;
            } else if (gatewayType == "BALANCE" && this.balanceCheck.length > 0) {
                _data.methodId = this.balanceCheck[0];
                this.bLoading = true;
            } else if (gatewayType == "UNIONPAY" && this.unionpayCheck.length > 0) {
                _data.methodId = this.unionpayCheck[0];
                this.uLoading = true;
            } else if (gatewayType == "PCREDIT" && this.acpayCheck.length > 0) {
                _data.methodId = this.acpayCheck[0];
                this.acLoading = true;
            }
            this.$http.post("payClientMethod/modify", _data).then(data => {
                this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1000
                });
                this.wLoading = false;
                this.aLoading = false;
                this.bLoading = false;
                this.uLoading = false;
                this.acLoading = false;
                this.initSetting();
            }).catch(error => {
                console.log(error);
            });
        }
    }
}